<template>
	<mescroll-uni :ref="'mescrollRef'+i" @init="mescrollInit" @down="downCallback" @up="upCallback">
		<view class="flex-between" style="padding: 20rpx 30rpx 0;">
			<view v-for="(list, lindex) in groups" :key="lindex" :class="[lindex > 0 ? 'u-p-l-18' : '']"
				style="width: 100%;">
				<view v-for="(item, index) in list" :key="index" style="width: 100%"
					@click="jumpUrl(`/pages/other/comment/note?notesId=${ item.notesId }`)">
					<dynamic-card :item="item"></dynamic-card>
				</view>
			</view>
		</view>
	</mescroll-uni>
</template>

<script>
	import waterfall from '@/utils/waterfall.js'
	import {
		notesPage
	} from '@/api/user/notes.js'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";

	export default {
		mixins: [MescrollMixin, MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
		props: {
			i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
			index: { // 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
				type: Number,
				default () {
					return 0
				}
			},
			merchantId: {
				default: ''
			}
		},
		data() {
			return {
				leftRightHeight: [0, 0],
				groups: [
					[],
					[]
				]
			}
		},
		// mounted() {
		// 	uni.$on('update-note-page', () => {
		// 		this.downCallback()
		// 	})
		// },
		methods: {
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				let node = this.$refs['mescrollRef' + this.i]
				let queryObj = {}
				this.merchantId && (queryObj.merchantId = this.merchantId);
				!this.i && (queryObj.isFollow = 1)
				notesPage({
					pageNumber: page.num,
					pageSize: page.size,
					...queryObj
				}).then(res => {
					if (page.num == 1) {
						this.groups = [
							[],
							[]
						]
						this.leftRightHeight = [0, 0]
					}; //如果是第一页需手动制空列表
					waterfall({
						hs: this.leftRightHeight,
						list: res.list,
						key: 'imgUrls'
					}, (hs, e) => {
						node && node.mescroll.endSuccess(res.list.length);
						this.leftRightHeight = hs
						this.groups = [
							[...this.groups[0], ...e[0]],
							[...this.groups[1], ...e[1]]
						]
					})
				}).catch(() => {
					node && node.mescroll.endErr();
				})
			},
			downCallback() {
				let node = this.$refs['mescrollRef' + this.i]
				node && node.mescroll.resetUpScroll()
			},
		}
	}
</script>
